{layout name="common/base" }
<script src="__PUBLIC__/js/common.js?b41"></script>
<div class="layuimini-container">
    <form action="" class="layui-form" id="myform" lay-filter="form-filter">
        <div class="layuimini-main">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this">隐私协议</li>
                    <li>用户协议</li>
                    <li>代理协议</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show" style="width:750px;">
                        <textarea id="editor0" style="display: none;">{$data[0]['content']}</textarea>
                    </div>

                    <div class="layui-tab-item" style="width:750px;">
                        <textarea id="editor1" style="display: none;">{$data[1]['content']}</textarea>
                    </div>

                    <div class="layui-tab-item" style="width:750px;">
                        <textarea id="editor2" style="display: none;">{$data[2]['content']}</textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" id='btnSubmit' lay-submit="" lay-filter="*">立即提交</button>
            </div>
        </div>
        <div>{:token()}</div>
    </form>
</div>

<script>
    layui.use(['form','layedit'], function () {
        var layedit = layui.layedit
            , layer = layui.layer
            , $ = layui.$;
        layedit.set({
            uploadImage: {
                url: "/admin/image/layUploadNo",
                type: 'post'
            }
        });

        var edit_content0 = layedit.build('editor0'); //建立编辑器
        var edit_content1 = layedit.build('editor1'); //建立编辑器
        var edit_content2 = layedit.build('editor2'); //建立编辑器

        layui.form.on('submit(*)', function (data) {
            var agreementData = {
                content0: layedit.getContent(edit_content0),
                content1: layedit.getContent(edit_content1),
                content2: layedit.getContent(edit_content2),
            }
            var url = '/admin/system.agreement/edit';
            // 发送ajax请求
            layObj.post(url, agreementData,  (res) =>{
                layer.msg(res.msg, {
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){
                    console.log(res);
                    if(res.code == 1){
                        // 关闭弹出层
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                        parent.layer.close(index); //再执行关闭
                    }else{

                    }
                });
            });

            return false;

        });

    });

</script>

